package com.activities;

import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.Utility.Base64;
import com.Utility.Utility;
import com.senditcertified.mail.Password;
import com.senditcertified.mail.R;
import com.senditcertified.mail.R.id;
import com.senditcertified.mail.R.layout;
import com.parser.Error_Report;
import com.parser.Parser_Soap;
import com.soap.call.Http_Soap_Call;

public class UserSecurityActivity extends Activity {
	/** Called when the activity is first created. */
	// private EditText username,password;
	// private Button login;
	ProgressDialog pd;
	ImageView imag;
	Bitmap Image;
	ViewFlipper flipper;
	boolean isShownext=false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.user_security_login);
	 
		String result=getIntent().getExtras().getString("Image");
		if(result!=null){
			byte image[];
			try {
				image = Base64.decode(result);
				Image= BitmapFactory.decodeByteArray(image, 0, image.length);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		findViewByID();
		/*
		 * login.setOnClickListener(new OnClickListener() {
		 * 
		 * @Override public void onClick(View v) { if
		 * (TextUtils.isEmpty(username.getText().toString())) {
		 * Toast.makeText(User_Security_Activity.this, "plz enter your email",
		 * Toast.LENGTH_SHORT) .show(); return;
		 * 
		 * } else if(!Utility.isEmailValid((username.getText().toString()))){
		 * Toast.makeText(User_Security_Activity.this,
		 * "plz enter valid email address", Toast.LENGTH_SHORT) .show(); return;
		 * } new LoginOnlineTask().execute(username.getText().toString()); } });
		 */

		// Http_Soap_Call call = Http_Soap_Call.create_connection("", this);
		// parse.GetLoginToken(call.GetLoginToken("zxzx@dd.com", "123456"));
		// parse.GetTime(call.GetTime());
		// call.GetUser("fff", "dfdf");
		// parse.GetUser(call.GetUser("fff", "dfdf"));
		// call.GetUserSecurityImage("dffdfdf");
	}

	private void findViewByID() {
		// username = (EditText) findViewById(R.id.username);
		// password= (EditText) findViewById(R.id.password);
		// login = (Button) findViewById(R.id.login_btn);
		imag = (ImageView) findViewById(R.id.user_security_img);
		imag.setImageBitmap(Image);
		flipper = (ViewFlipper)findViewById(R.id.flipper);
	}

	public void yes(View v) {

		Intent mainIntent = new Intent(UserSecurityActivity.this,
				Password.class);
		mainIntent.putExtra("Username", getIntent().getExtras().getString("Username"));
		UserSecurityActivity.this.startActivity(mainIntent);
		UserSecurityActivity.this.finish();

	}

	public void no(View v) {
		/*AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("Sory we can not proceed further?")
				.setCancelable(false)
				.setPositiveButton("ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						// put your code here
						dialog.dismiss();
						finish();
					}
				});

		AlertDialog alertDialog = builder.create();
		alertDialog.show();*/
		flipper.showNext();
		isShownext=true;
		
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		//super.onBackPressed();
		if(isShownext){
			flipper.showPrevious();
			isShownext=false;
		}
		else{
			finish();
		}
	}
	
	/*
	 * class LoginOnlineTask extends AsyncTask<String, Void, Boolean> { boolean
	 * result = false; //String error_msg = ""; String Result=null; Parser_Soap
	 * parse=new Parser_Soap(); Error_Report repor=new Error_Report();
	 * 
	 * @Override protected Boolean doInBackground(String... params) {
	 * Http_Soap_Call call = Http_Soap_Call.create_connection("",
	 * User_Security_Activity.this); if(call!=null) { Result=
	 * parse.GetUserImage(call.GetUserSecurityImage(params[0],repor),repor);
	 * if(Result!=null){ System.out.println("true"); result=true; } else{
	 * //error_msg=Utility.INVALID_USER; System.out.println("false");
	 * result=false; repor.setMessage("Internal Error"); }
	 * 
	 * 
	 * } else{ repor.setMessage(Utility.NETWORK_ISSUE); return false; }
	 * 
	 * return result; }
	 * 
	 * @Override protected void onPreExecute() { pd =
	 * ProgressDialog.show(User_Security_Activity.this, null,
	 * getString(R.string.loader)); }
	 * 
	 * protected void onPostExecute(Boolean result) { // This method runs in the
	 * UI thread
	 * 
	 * pd.dismiss(); if(result){ //Utility.printLog("Login Responce",
	 * "Login successfully");
	 * 
	 * try { byte image[]=Base64.decode(Result); Bitmap decodedByte =
	 * BitmapFactory.decodeByteArray(image, 0, image.length);
	 * imag.setImageBitmap(decodedByte);
	 * 
	 * } catch (IOException e) { // TODO Auto-generated catch block
	 * e.printStackTrace(); }
	 * 
	 * } else{ Utility.printLog("Login Responce", "Login Unsuccessfully");
	 * Toast.makeText(User_Security_Activity.this, repor.getMessage(),
	 * Toast.LENGTH_SHORT).show(); }
	 * 
	 * } }
	 */

}